package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.ProductCategory;

import com.briup.jz.service.IProductCategoryService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="产品-种类")
@Validated
@RestController
@RequestMapping("/productCategory")

public class ProductCategoryController {
	@Autowired//注入接口
    private IProductCategoryService productCategoryService;
	
	 //查
    @ApiOperation(value = "查询所有产品对应的种类")
    @GetMapping("query")
    public Message query(Long id){
        List<ProductCategory> list = productCategoryService.query(id);
        return MessageUtil.success(list);
    }
    
  //删
    @ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
    	productCategoryService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
    

  //增 改
    @ApiOperation(value = "保存或更新资讯分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "产品种类id",paramType = "form"),
            @ApiImplicitParam(name="name",value = "产品服务名称",paramType = "form",required = true),
            @ApiImplicitParam(name="icon",value = "产品相应图标",paramType = "form"),
            @ApiImplicitParam(name="num",value = "产品剩余数量",paramType = "form"),
            @ApiImplicitParam(name="parentId",value = "该产品归属于的产品类型id",paramType = "form"),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(ProductCategory productCategory){
    	productCategoryService.saveOrUpdate(productCategory);
        return MessageUtil.success("更新成功");
    }
	

}
